package com.seal.commons.infrastructure.facade.distributed.lock;


import java.util.function.Supplier;

/**
 * ClassName:AbstractDistributedLock <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:  TODO ADD REASON. <br/>
 * Date:     2019-04-15 14:40 <br/>
 *
 * @author yong.huang
 * @see
 * @since JDK 1.8
 */
public abstract class AbstractDistributedLock implements DistributedLock {


    @Override
    public boolean lock(String key) {
        return lock(key, TIMEOUT_MILLIS, RETRY_TIMES, SLEEP_MILLIS );
    }

    @Override
    public boolean lock(String key, int retryTimes) {
        return lock(key,TIMEOUT_MILLIS, retryTimes, SLEEP_MILLIS);
    }

    @Override
    public boolean lock(String key, int retryTimes, long sleepMillis) {
        return lock(key,TIMEOUT_MILLIS, retryTimes, sleepMillis);
    }

    @Override
    public boolean lock(String key, long expire) {
        return lock(key, expire, RETRY_TIMES, SLEEP_MILLIS );
    }

    @Override
    public boolean lock(String key, long expire, int retryTimes) {
        return lock(key, expire, retryTimes, SLEEP_MILLIS );
    }

    @Override
    public <T> T acquire(String key, Supplier<T> supplier) {
        return acquire(key, TIMEOUT_MILLIS, RETRY_TIMES, SLEEP_MILLIS, supplier);
    }

    @Override
    public <T> T acquire(String key, long expire, Supplier<T> supplier) {
        return acquire(key, expire, RETRY_TIMES, SLEEP_MILLIS, supplier);
    }

    @Override
    public <T> T acquire(String key, long expire, int retryTimes, Supplier<T> supplier) {
        return acquire(key, expire, retryTimes, SLEEP_MILLIS, supplier);
    }
}
